ListView Selection

I may be missing something here. But I wonder how to figure out which item is selected in a single ListView when Sorting is allowed.

So if each row in the ListView represents an Object and I gather some Objects and display each in a row in a ListView and keep track of that in an Array, and the user sorts that list view and then selects row a row, I know I can determine that its row #4 but I wonder how I know which Object it represents since the current 4th row is not the 4th Object in the Array.

I see the "string get(dbeListView, iRow)" command will return, for single listviews, the value in the 1st column of that row. I thus resolve my issue by making sure the 1st column is always some unique identifier, in this case the AbsNo or ObjectID, and then use that info to look up the Object in my Array using a Skip list of ObjIDs to Array Indexes. In other cases when I build the ListView the 1st column is simply the Array Index, inserted row X column 0 has value "X".

But it seems like there should be a better way than forcing the 1st column to be an index.

  • Louie

llandale - Thu Sep 08 10:52:57 EDT 2011

Re: ListView Selection
Mathias Mamsch - Thu Sep 08 16:55:40 EDT 2011

Hmm I thought you would be able to use the client data field on the rows, but obviously at least for DOORS 8.2 this is implemented buggy. As soon as you add the listViewOptionSortText at the creation of the listview, then the below code crashes. Until this is fixed I guess you either need that index column (make it width 0) or stay away from sorting. Regards, Mathias
 

int    fDbeLv_clbkSortFunction(string s1, s2)
{     // Standard sort function when defining a column as sortable.
        // Developers Note: Some code if added herein will cause DXL exception Violations.
        //      Don't understand why, but this function needs to be kept as-is.
        int     Result
        print "S1 = " s1 " S2 = " s2 "\n"
        if     (s1 == s2) Result =  0
        elseif (s1 >  s2) Result =  1
        elseif (s1 <  s2) Result = -1
        else{} // all cases covered
        return(Result)
}  // end fDbeLv_clbkSortFunction()
 
 
DBE lv 
 
void activateModule (DBE x, int index) {
        print "I = " index " activated!\n"
        if (index < 0) return 
        Buffer s = (getClientData(lv, index)) Buffer
        print s "\n"
}             
 
string someData[] = {}
 
DB testDialog = centered "Listview Test"
 
label (testDialog, "" )
// remove the listViewOptionSortText and the code will not crash
lv = listView (testDialog,listViewOptionSortText, 200, 5, someData)
 
realize testDialog
 
insertColumn(lv, 0, "Column 1"       , 80, iconNone)
insertColumn(lv, 1, "Column 2"       , 80, iconNone)
 
set (lv, 0, 1, "Some Data")
set (lv, 1, 1, "More Data")
 
set(lv, 0, fDbeLv_clbkSortFunction)
set(lv, 1, fDbeLv_clbkSortFunction)
 
void dummyCallback(DBE, int) {}
set(lv, dummyCallback, dummyCallback, activateModule)   
 
Buffer b1 = create(); b1 = "This is Index 1"
Buffer b2 = create(); b2 = "This is Index 2"
insert(lv, 0,  "Line 1", b1, iconNone) 
insert(lv, 1,  "Line 2", b2, iconNone) 
 
show testDialog

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

 

Re: ListView Selection
Tony_Goodman - Fri Sep 09 11:26:06 EDT 2011

Mathias Mamsch - Thu Sep 08 16:55:40 EDT 2011

Hmm I thought you would be able to use the client data field on the rows, but obviously at least for DOORS 8.2 this is implemented buggy. As soon as you add the listViewOptionSortText at the creation of the listview, then the below code crashes. Until this is fixed I guess you either need that index column (make it width 0) or stay away from sorting. Regards, Mathias
 

int    fDbeLv_clbkSortFunction(string s1, s2)
{     // Standard sort function when defining a column as sortable.
        // Developers Note: Some code if added herein will cause DXL exception Violations.
        //      Don't understand why, but this function needs to be kept as-is.
        int     Result
        print "S1 = " s1 " S2 = " s2 "\n"
        if     (s1 == s2) Result =  0
        elseif (s1 >  s2) Result =  1
        elseif (s1 <  s2) Result = -1
        else{} // all cases covered
        return(Result)
}  // end fDbeLv_clbkSortFunction()
 
 
DBE lv 
 
void activateModule (DBE x, int index) {
        print "I = " index " activated!\n"
        if (index < 0) return 
        Buffer s = (getClientData(lv, index)) Buffer
        print s "\n"
}             
 
string someData[] = {}
 
DB testDialog = centered "Listview Test"
 
label (testDialog, "" )
// remove the listViewOptionSortText and the code will not crash
lv = listView (testDialog,listViewOptionSortText, 200, 5, someData)
 
realize testDialog
 
insertColumn(lv, 0, "Column 1"       , 80, iconNone)
insertColumn(lv, 1, "Column 2"       , 80, iconNone)
 
set (lv, 0, 1, "Some Data")
set (lv, 1, 1, "More Data")
 
set(lv, 0, fDbeLv_clbkSortFunction)
set(lv, 1, fDbeLv_clbkSortFunction)
 
void dummyCallback(DBE, int) {}
set(lv, dummyCallback, dummyCallback, activateModule)   
 
Buffer b1 = create(); b1 = "This is Index 1"
Buffer b2 = create(); b2 = "This is Index 2"
insert(lv, 0,  "Line 1", b1, iconNone) 
insert(lv, 1,  "Line 2", b2, iconNone) 
 
show testDialog

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

 

I have done a lot of sortable list views, and yes you do need an index column that contains some sort of unique identifier for the row. It can be in any position and does not to be column 0.

As Mathias says, sort functions are very buggy. Do not try to do anything clever in the callback - it always blows up.
Tony Goodman, www.smartdxl.com

Re: ListView Selection
llandale - Fri Sep 09 11:49:42 EDT 2011

Mathias Mamsch - Thu Sep 08 16:55:40 EDT 2011

Hmm I thought you would be able to use the client data field on the rows, but obviously at least for DOORS 8.2 this is implemented buggy. As soon as you add the listViewOptionSortText at the creation of the listview, then the below code crashes. Until this is fixed I guess you either need that index column (make it width 0) or stay away from sorting. Regards, Mathias
 

int    fDbeLv_clbkSortFunction(string s1, s2)
{     // Standard sort function when defining a column as sortable.
        // Developers Note: Some code if added herein will cause DXL exception Violations.
        //      Don't understand why, but this function needs to be kept as-is.
        int     Result
        print "S1 = " s1 " S2 = " s2 "\n"
        if     (s1 == s2) Result =  0
        elseif (s1 >  s2) Result =  1
        elseif (s1 <  s2) Result = -1
        else{} // all cases covered
        return(Result)
}  // end fDbeLv_clbkSortFunction()
 
 
DBE lv 
 
void activateModule (DBE x, int index) {
        print "I = " index " activated!\n"
        if (index < 0) return 
        Buffer s = (getClientData(lv, index)) Buffer
        print s "\n"
}             
 
string someData[] = {}
 
DB testDialog = centered "Listview Test"
 
label (testDialog, "" )
// remove the listViewOptionSortText and the code will not crash
lv = listView (testDialog,listViewOptionSortText, 200, 5, someData)
 
realize testDialog
 
insertColumn(lv, 0, "Column 1"       , 80, iconNone)
insertColumn(lv, 1, "Column 2"       , 80, iconNone)
 
set (lv, 0, 1, "Some Data")
set (lv, 1, 1, "More Data")
 
set(lv, 0, fDbeLv_clbkSortFunction)
set(lv, 1, fDbeLv_clbkSortFunction)
 
void dummyCallback(DBE, int) {}
set(lv, dummyCallback, dummyCallback, activateModule)   
 
Buffer b1 = create(); b1 = "This is Index 1"
Buffer b2 = create(); b2 = "This is Index 2"
insert(lv, 0,  "Line 1", b1, iconNone) 
insert(lv, 1,  "Line 2", b2, iconNone) 
 
show testDialog

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

 

never seen that 'clientData' stuff before. Using v9201 and geting the exceptions as you are unless its not sortable. Tried to change the clientData from Buffer to String but it didn't work. Oh well. but I don't need the clientData if the ListView isn't sorted since the iSelectedRow will match exactly what I inserted originally.

After my post I did find this command: getColumnValue(DBE lv, int iRow, int iColumn) which means my KEY column need not be the first one.

Thanks

  • Louie

Re: ListView Selection
llandale - Fri Sep 09 11:54:21 EDT 2011

Tony_Goodman - Fri Sep 09 11:26:06 EDT 2011
I have done a lot of sortable list views, and yes you do need an index column that contains some sort of unique identifier for the row. It can be in any position and does not to be column 0.

As Mathias says, sort functions are very buggy. Do not try to do anything clever in the callback - it always blows up.
Tony Goodman, www.smartdxl.com

I notice that Mathias' example successfully added a print statement to the sort callback, and when you add another row I see that the callback is called for each sort, and it appears to be a buble-sort algorithm. I specifically recall however that when I tried to tweak the callback that it would blow up, but I don't recall the details.

I wonder if you can re-define the callback such that you can enforce a reverse sort on demand. It would getSortColumn and if its the same column, reverse the sort order.

  • Louie